//package cn.heygod.nacostool.session;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.core.annotation.Order;
//
//import javax.servlet.*;
//import javax.servlet.annotation.WebFilter;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.util.Arrays;
//import java.util.Collections;
//import java.util.HashSet;
//import java.util.Set;
//
///**
// * @Author Simon
// */
//@WebFilter(urlPatterns = "/*")
//@Order(value = 1)
//public class LoginFilter implements Filter {
//
//    private Logger logger = LoggerFactory.getLogger(getClass());
//    private static final Set<String> ALLOWED_PATHS = Collections.unmodifiableSet(new HashSet<>(
//            Arrays.asList("/login.html", "/api/login", "/api/logout", "/api/register")));
//
//    public static final String LOGIN_PAGE = "/deploy-web/login.html";
//
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//    }
//
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//            HttpServletRequest request = (HttpServletRequest) servletRequest;
//            HttpServletResponse response = (HttpServletResponse) servletResponse;
//            String path = request.getRequestURI();
//            boolean allowedPath = ALLOWED_PATHS.contains(path);
//
//            if (allowedPath) {
//                filterChain.doFilter(servletRequest, servletResponse);
//            }else {
//                logger.info("The request is not logged in, automatically redirecting to the login page");
//                response.sendRedirect(LOGIN_PAGE);
//            }
//    }
//
//    @Override
//    public void destroy() {
//        Filter.super.destroy();
//    }
//
//}
